var app = getApp()
Page({
  data: {
    order_id:0,
    totalFee:0
  },
  pay() {
    let self = this;
    wx.getStorage({
      key: 'token',
      success: function (res) {
        console.log(res)
        var member_id = res.data.member_id
        var openid = res.data.openid
        self.payment(openid)
      },
      fail: (res) => {
        wx.navigateTo({
          url: '/page/component/login/index',
        })
      }
    })
  },
  payment(openid){
    let self = this
    app.request({
      url:'/common/pay',
      method:'post',
      data:{
        order_id: self.data.order_id,
        openid: openid
      },
      success:(res)=>{
        console.log(res)
        wx.requestPayment({
          timeStamp: res.result.msg.timeStamp,
          nonceStr: res.result.msg.nonceStr,
          package: res.result.msg.package,
          signType: res.result.msg.signType,
          paySign: res.result.msg.paySign,
          success(res) {
            wx.redirectTo({
              url: '../paySuccess/index?type=true'
            })
          },
          fail(res) {
            wx.redirectTo({
              url: '../paySuccess/index?type=false'
            })
          }
        })
      }
    })
  },
  guanbi() {
    wx.navigateBack({
      
    })
    // wx.redirectTo({
    //   url: "/page/userCenter/orderList/index"
    // })
  },
  onLoad: function (options) {
    if(options && options.order_id){
      app.request({
        url:'/home/order/getInfo',
        method:'post',
        data:{
          order_id:options.order_id
        },
        success:(res)=>{
          this.setData({
            order_id: options.order_id,
            totalFee: parseFloat(res.result.room_price).toFixed(2)
          })
        }
      })
    }
  },
  onShow: function () {

  }
})